package com.aidex.biz.service.impl;

import com.aidex.biz.domain.EquInfo;
import com.aidex.biz.mapper.EquInfoMapper;
import com.aidex.biz.service.EquInfoService;
import com.aidex.common.annotation.DataScope;
import com.aidex.common.core.redis.RedisCache;
import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.common.utils.NumberUtils;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 设备信息Service业务层处理
 * @author sean
 * @email 2074844820@qq.com
 * @date 2022-09-22
 */
@Service
@Transactional(readOnly = true)
public class EquInfoServiceImpl extends BaseServiceImpl<EquInfoMapper, EquInfo> implements EquInfoService
{
    private static final Logger log = LoggerFactory.getLogger(EquInfoServiceImpl.class);
    @Autowired
    private RedisCache redisCache;

    /**
     * 获取单条数据
     * @param equInfo 设备信息
     * @return 设备信息
     */
    @Override
    public EquInfo get(EquInfo equInfo)
    {
        EquInfo dto = super.get(equInfo);
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 设备信息id
     * @return 设备信息
     */
    @Override
    public EquInfo get(String id)
    {
        EquInfo dto = super.get(id);
        return dto;
    }


    /**
     * 查询设备信息列表
     * @param equInfo 设备信息
     * @return 设备信息
     */
    @Override
    @DataScope(userAlias = "a",deptAlias = "a")
    public List<EquInfo> findList(EquInfo equInfo)
    {
        return super.findList(equInfo);
    }

    /**
     * 分页查询设备信息列表
     * @param equInfo 设备信息
     * @return 设备信息
     */
    @Override
    @DataScope(userAlias = "a",deptAlias = "a")
    public PageInfo<EquInfo> findPage(EquInfo equInfo)
    {
        return super.findPage(equInfo);
    }

    /**
     * 保存设备信息
     * @param equInfo
     * @return 结果
     */
    @Override
    public boolean save(EquInfo equInfo)
    {
        return super.save(equInfo);
    }


    /**
     * 删除设备信息信息
     * @param equInfo
     * @return 结果
     */
    @Override
    public boolean remove(EquInfo equInfo)
    {
        return super.remove(equInfo);
    }

    /**
     * 批量删除设备信息
     * @param ids 需要删除的设备信息ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteEquInfoByIds(String[] ids)
    {
        return mapper.deleteEquInfoByIds(ids);
    }

    /**
     * 获取最大编号
     * @param equInfo 设备信息
     * @return 结果
     */
    @Override
    public int findMaxSort(EquInfo equInfo)
    {
        return NumberUtils.nextOrder(mapper.findMaxSort(equInfo));
    }

    @Override
    public EquInfo getRedisEquInfo(String companyId) {
        EquInfo equInfo=redisCache.getCacheObject("yz"+companyId);
        if(null==equInfo){
            equInfo=new EquInfo();
            equInfo.setCompanyId(companyId);
            List<EquInfo> equInfos=findList(equInfo);
            equInfo=equInfos.size()>0?equInfos.get(0):null;
            redisCache.setCacheObject("yz"+companyId,equInfo);
        }
        return equInfo;
    }

    @Override
    public PageInfo<EquInfo> getRedisEquInfoList(EquInfo equInfo) {
//        PageInfo<EquInfo> equInfoPageInfo=redisCache.getCacheObject("equInfoList");
//        if(null==equInfoPageInfo){
//            equInfoPageInfo=this.findPage(equInfo);
//            redisCache.setCacheObject("equInfoList",equInfoPageInfo);
//        }
        return this.findPage(equInfo);
    }
}
